using System;
using System.Collections.Generic;
using System.Linq;
namespace HF.Repository
{

    public class GenericPoolObject<T>
    {
        public T PoolObject
        {
            get;
            set;
        }
        public bool IsFree
        {
            get;
            set;
        }
    }
    public class GenericPool<T> where T : IEquatable<T>, new()
    {
        private List<GenericPoolObject<T>> list = new List<GenericPoolObject<T>>();

        public T GetPoolObject()
        {
            var obj = list.FirstOrDefault(p => p.IsFree) ??
                      new GenericPoolObject<T> { PoolObject = new T(), IsFree = true };
            obj.IsFree = false;
            return obj.PoolObject;
        }
        public void ReturnPoolObject(T obj)
        {
            var obj1 = list.FirstOrDefault(p => p.PoolObject.Equals(obj));
            obj1.IsFree = true;
        }
    }
}